<?php
namespace app\index\controller;

use think\Controller;

/**
 * 路径测试控制器
 */
class PathTest extends Controller
{
    public function index()
    {
        $paths = [
            'Current __DIR__' => __DIR__,
            'Project root (calculated)' => dirname(dirname(dirname(dirname(__DIR__)))),
            'Excel path (relative)' => dirname(dirname(dirname(dirname(__DIR__)))) . '/doc/sbb.xlsx',
            'Excel path (absolute)' => 'F:/phpstudy_pro/intvale/ai_1/doc/sbb.xlsx',
        ];

        echo "<h2>路径测试结果</h2>";
        foreach ($paths as $label => $path) {
            $exists = file_exists($path) ? '✓ 存在' : '✗ 不存在';
            $color = file_exists($path) ? 'green' : 'red';
            echo "<p><strong>{$label}:</strong> <span style='color: {$color};'>{$path} ({$exists})</span></p>";
        }

        // 测试doc目录
        $docDir = 'F:/phpstudy_pro/intvale/ai_1/doc';
        echo "<h3>doc目录内容:</h3>";
        if (is_dir($docDir)) {
            $files = scandir($docDir);
            foreach ($files as $file) {
                if ($file != '.' && $file != '..') {
                    echo "<p>- {$file}</p>";
                }
            }
        } else {
            echo "<p style='color: red;'>doc目录不存在</p>";
        }

        return json([
            'paths' => $paths,
            'excel_exists' => file_exists('F:/phpstudy_pro/intvale/ai_1/doc/sbb.xlsx')
        ]);
    }
}